-- SkySequence
-- create by chendh
-- 天空之城战斗的播放序列(界面表现)

require("game/ui/base/ActionState");
require("game/ui/sequence/action/ActionBase");
require("game/ui/sky_sequence/action/SCAttackAction");
require("game/ui/sky_sequence/action/SCBuffAction");
require("game/ui/sky_sequence/action/SCCureAction");
require("game/ui/sky_sequence/action/SCDebuffAction");
require("game/ui/sky_sequence/action/SCDelayAction");
require("game/ui/sky_sequence/action/SCDamageAction");
require("game/ui/sky_sequence/action/SCPropEffectAction");
require("game/ui/sky_sequence/action/SCRefreshMonsterAction");

-- 播放序列
SkySequence = class("SkySequence");

--构造函数
function SkySequence:ctor(fighter)
    self.fighter = fighter;

    -- 初始化
    self.actionSequence = {};

    self.isFree = true;
end

-- 更新fighter
function SkySequence:updateFighter(fighter)
    self.fighter = fighter;
end

-- 判断是否有序列需要播放
function SkySequence:isEmpty()
    local num = #self.actionSequence;
    return num == 0;
end

-- 播放序列, 每次只播放一个，并返回当前序列需要的时间
function SkySequence:play()
    if #self.actionSequence > 0 then
        self.isFree = false;

        local action = self.actionSequence[1];
        table.removeItem(self.actionSequence, action);
        local delay = action:play();

        if delay == nil or delay <= 0 then
            self:play();
        else
            local uiCombat = UIMgr.getCurrentScene():getFormByName("UISkyCityCombat");
            performWithDelay(uiCombat, function()
                self:play();
            end, delay);
        end
    else
        self.isFree = true;
    end
end

-- 添加攻击行为表现
function SkySequence:attack(source, target, skillId, args)
    -- 攻击行为
    table.insert(self.actionSequence, SCAttackAction.create(source, target, skillId, args));
end

-- 添加延迟行为表现
function SkySequence:delay(delay)
    -- 延迟行为
    table.insert(self.actionSequence, SCDelayAction.create(delay));
end

-- 添加受创攻击行为表现
function SkySequence:receiveDamage(target, skillId, damage, args)
    if damage <= 0 then
        return;
    end

    -- 受创行为
    table.insert(self.actionSequence, SCDamageAction.create(target, skillId, damage, args));
end

-- 添加治疗行为表现
function SkySequence:cure(source, target, skillId, args)
    -- 治疗行为
    table.insert(self.actionSequence, SCCureAction.create(source, target, skillId, args));
end

-- 添加增益状态行为表现
function SkySequence:addBuff(source, target, skillId, args)
    -- 添加增益状态行为
    table.insert(self.actionSequence, SCBuffAction.create(source, target, skillId, args));
end

-- 添加负面状态行为表现
function SkySequence:addDebuff(target, skillId, effect)
    -- 添加负面行为
    table.insert(self.actionSequence, SCDebuffAction.create(target, skillId, effect));
end

-- 添加属性触发行为表现
function SkySequence:addPropEffect(source, args)
    -- 添加属性触发行为
    table.insert(self.actionSequence, SCPropEffectAction.create(source, args))
end

-- 添加刷新怪物的属性
function SkySequence:addRefreshMonster(source, args)
    -- 添加刷新怪物行为
    table.insert(self.actionSequence, SCRefreshMonsterAction.create(source, args));
end

return SkySequence;
